/*
** P 5 6 
*/

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

typedef struct group* PtrToNode;
typedef PtrToNode Node;
typedef int ElementType;
struct group {
    ElementType Data;
    PtrToNode Next;
};

void AddNode ( Node N, ElementType X, PtrToNode rear ) {
    Node tmp;
    // 1. init 
    tmp = (Node)malloc(sizeof(struct group));
    tmp->Data = X;
    tmp->Next = NULL;
    // 2. link
    rear->Next = tmp;
}

int main () {
    int K;
    ElementType X;
    scanf("%d",&K);
    scanf("%d",&X);
    Node N = (Node)malloc(sizeof(struct group));
    N->Data = X;
    N->Next = NULL;
    PtrToNode rear = N, p = N;
    while ( K-- ) {
        scanf("%d",&X);
        if ( X == -1 ) {
            if ( K != 0 ) {
                printf("NULL");
                exit(-3);
            }  else {
                printf("%d",rear->Data);
                exit(0);            }
        }
        AddNode(N,X,rear);
        rear = rear->Next;
    }
    while (1) {
        p = p->Next;
        scanf("%d",&X);
        if ( X == -1 ) break;
        AddNode(N,X,rear);
        rear = rear->Next;
    }
    printf("%d",p->Data);
    return 0;
}